package com.crh.bean;

import java.util.List;

public class Page {
    private List records;//纪录得不同对象
    private int currentPage;//当前页
    private int totalPage;//总页数
    private int totalRecodes;//总纪录数
    private int pageSize;//每页要显示的纪录数

    //用户查询数据库使用的参数
    private int startIndex;//每页纪录开始的索引
    private int endIndex;//每页纪录结束的索引
    //页面显示的页面
    private int prevPage;//上一页
    private int nextPage;//下一页

    //传入当前页、以及总纪录数、以及每页显示纪录数
    public Page(int currentPage, int totalRecodes, int pageSize) {
        this.currentPage = currentPage;
        this.totalRecodes = totalRecodes;
        this.pageSize = pageSize;
        //总页数
        //totalPage = totalRecodes % pageSize == 0 ? totalRecodes / pageSize : totalRecodes / pageSize + 1;
          totalPage = totalRecodes % pageSize == 0 ? totalRecodes / pageSize : totalRecodes / pageSize + 1;
        //判断当前页是否已经是首页、或者尾页、
        prevPage = currentPage - 1 > 0 ? currentPage - 1 : 1;
//        nextPage = currentPage + 1 > totalRecodes ? currentPage : currentPage + 1;
        nextPage = currentPage + 1 > totalPage ? currentPage : currentPage+1 ;
        //计算每页开始的索引值
        startIndex = (currentPage - 1) * pageSize;
        endIndex = currentPage * pageSize + 1;
    }

    public List getRecords() {
        return records;
    }

    public void setRecords(List records) {
        this.records = records;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getTotalRecodes() {
        return totalRecodes;
    }

    public void setTotalRecodes(int totalRecodes) {
        this.totalRecodes = totalRecodes;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getEndIndex() {
        return endIndex;
    }

    public void setEndIndex(int endIndex) {
        this.endIndex = endIndex;
    }

    public int getPrevPage() {
        return prevPage;
    }

    public void setPrevPage(int prevPage) {
        this.prevPage = prevPage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    @Override
    public String toString() {
        return "Page{" +
                "records=" + records +
                ", currentPage=" + currentPage +
                ", totalPage=" + totalPage +
                ", totalRecodes=" + totalRecodes +
                ", pageSize=" + pageSize +
                ", startIndex=" + startIndex +
                ", endIndex=" + endIndex +
                ", prevPage=" + prevPage +
                ", nextPage=" + nextPage +
                '}';
    }
}
